import Vue from 'vue';

import axios from 'axios';

axios.defaults.baseURL = process.env.VUE_APP_API_URL;
axios.defaults.timeout = 50 * 1000;
axios.defaults.timeoutErrorMessage = '请求超时';

axios.interceptors.request.use(config => {
    let openid;
    try{
        openid = JSON.parse(localStorage.wxInfo).wxOpenId;
    }catch (e) {
        openid = '';
    }
    config.headers['openId'] = openid;
    //config.headers['openId'] = '1';
    //console.log('设置请求');
    return config;
}, err => {
    return Promise.reject(err);
});

axios.interceptors.response.use(response => {


    return response.data;

},error => {
    console.log(error);
    return Promise.reject(error);
});


Vue.prototype.$http = axios;
